package com.example.fragmenttest

import android.os.Bundle
import android.service.quicksettings.Tile
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER


/**
 * A simple [Fragment] subclass.
 * Use the [NewsContentFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class NewsContentFragment : Fragment() {

    private lateinit var contentLayout: LinearLayout
    private lateinit var newsTitle: TextView
    private lateinit var newsContent: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_news_content, container, false)
    }
    // 在 onViewCreated 中绑定控件（布局已加载，可安全调用 findViewById）
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // 绑定布局中的控件（ID 必须与 fragment_news_content.xml 中的对应控件一致）
        contentLayout = view.findViewById(R.id.contentLayout) // 根布局 LinearLayout
        newsTitle = view.findViewById(R.id.newsTitle)         // 新闻标题 TextView
        newsContent = view.findViewById(R.id.newsContent)   // 新闻内容 TextView
    }
    fun refresh(title: String, content: String){
        contentLayout.visibility = View.VISIBLE
        newsTitle.text = title
        newsContent.text = content
    }
}